package com.example.healkep;

import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.example.healkep.MainActivity.MainActivity;

public class FoodMainActivity extends AppCompatActivity {



    String name;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        if (getSupportActionBar() != null){
            getSupportActionBar().hide();
        }   //隐藏标题栏
        super.onCreate(savedInstanceState);
        setContentView(R.layout.food_activity_main);
        //view层的控件和业务层的控件，靠id关联和映射  赋值，即设置布局文件中的Button按钮id进行关联
        Button select1 = (Button) findViewById ( R.id.select1 );
        Button select3 = (Button) findViewById ( R.id.select3 );
        Button select4 = (Button) findViewById ( R.id.select4 );
        Button dietPlan = (Button) findViewById ( R.id.dietPlan);

        //绑定监听事件
        select1.setOnClickListener ( new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // 给bnt1添加点击响应事件
                Intent intent1 = new Intent ( FoodMainActivity.this, MainActivity.class );
                //启动
                startActivity ( intent1 );

            }
        } );

        select3.setOnClickListener ( new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // 添加点击响应事件
                Intent intent1 = new Intent ( FoodMainActivity.this, MainBg.class );
                //启动
                startActivity ( intent1 );

            }
        } );

        select4.setOnClickListener ( new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // 添加点击响应事件
                Intent intent1 = new Intent ( FoodMainActivity.this, MainUser.class );
                //启动
                startActivity ( intent1 );

            }
        } );

        dietPlan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // 添加点击响应事件
                Intent intent1 = new Intent ( FoodMainActivity.this, DietPlanActivity.class );
                //启动
                startActivity ( intent1 );

            }
        });
    }

    public void toBaseListTest(View view) {
        EditText editText=(EditText)findViewById(R.id.edittext);
        editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                Toast.makeText(FoodMainActivity.this, String.valueOf(actionId), Toast.LENGTH_SHORT).show();
                return false;
            }
        });
        editText.selectAll();
        int start=editText.getSelectionStart();
        int end=editText.getSelectionEnd();
        String selectText=editText.getText().subSequence(start, end).toString();//文本输入框
        name = selectText; //搜索食谱的名字

        CheckBox box_food = findViewById(R.id.food);
        CheckBox box_ingredients = findViewById(R.id.ingredients);
        CheckBox box_accessories = findViewById(R.id.accessories);

        Intent intent = new Intent(this, FoodBaseAdapterActivity.class);
        intent.putExtra("searchname", name);
        intent.putExtra("foodbox", box_food.isChecked());
        intent.putExtra("ingredientsbox", box_ingredients.isChecked());
        intent.putExtra("accessoriesbox", box_accessories.isChecked());
        startActivity(intent);
    }

    public void favorlist(View view) {
        String username = LoginActivity.getUser();
        Intent intent = new Intent(this, FoodFavorAdapterActivity.class);
        intent.putExtra("username", username);
        startActivity(intent);
    }
}